package com.woniuxy.Controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.RbacManager;
import com.woniuxy.entity.RbacManagerDto;
import com.woniuxy.service.RbacManagerService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (RbacManager)表控制层
 *
 * @author mayuhang
 * @since 2021-04-25 23:04:54
 */
@RestController
@RequestMapping("rbacManager")
public class RbacManagerController {
    /**
     * 服务对象
     */
    @Resource
    private RbacManagerService rbacManagerService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public RbacManager selectOne(Integer id) {
        return this.rbacManagerService.queryById(id);
    }
    @GetMapping("selectAll")
    public PageInfo<Map<String,String>> selectOne(int startpage,int pagesize) {
        PageHelper.startPage(startpage,pagesize);
        Page<Map<String,String>> page = (Page<Map<String,String>>) this.rbacManagerService.queryAllByLimit();
        PageInfo<Map<String,String>> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }

    @RequestMapping("addManager")
    public String addPerm(@RequestBody RbacManager RbacManager){
        this.rbacManagerService.insert(RbacManager);
        return "success";
    }

    @RequestMapping("deleteManager/{id}")
    public String deletePerm(@PathVariable int id){
        this.rbacManagerService.deleteById(id);
        return "success";
    }
    @RequestMapping("updateManager")
    public String updatePerm(@RequestBody RbacManager RbacManager){
        this.rbacManagerService.update(RbacManager);
        return "success";
    }
    @RequestMapping("search")
    public PageInfo<Map<String,String>> search(@RequestBody RbacManagerDto RbacManagerDto){
        System.out.println(RbacManagerDto.toString());
        PageHelper.startPage(RbacManagerDto.getPage(),RbacManagerDto.getLimit());
        List<Map<String,String>> search = this.rbacManagerService.search(RbacManagerDto.getRbacManager());
        Page<Map<String,String>> page = (Page) search;
        PageInfo<Map<String,String>> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }
}
